package application.easyui.datagrid.demo.controller;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;

import application.easyui.datagrid.demo.model.Application;
import application.easyui.datagrid.demo.model.ResponseResult;
import application.easyui.datagrid.demo.service.impl.ApplicationServiceImpl;

@Controller
public class ApplicationController {
	
	@Autowired
	private ApplicationServiceImpl applicationServiceImpl;
	
	@RequestMapping("/adds")
	public String applications(){
		return "/app";
	}
	
	@RequestMapping("/adds.do")
	public String application(){
		return "/application";
	}
	
	@RequestMapping("/add.do")
	public void add(Application application,HttpServletResponse response){
		response.setCharacterEncoding("UTF-8");
		applicationServiceImpl.add(application);
	}

	@RequestMapping("/del.do")
	public void delete(Integer id,HttpServletResponse response){
		response.setCharacterEncoding("UTF-8");
		applicationServiceImpl.delete(id);
	}
	
	@RequestMapping("/modify.do")
	public void modify(Application application,HttpServletResponse response){
		response.setCharacterEncoding("UTF-8");
		applicationServiceImpl.upload(application.getId(), application.getName(), application.getNation(), application.getAddress(), application.getNat(), application.getProvinces(), application.getHeight(), application.getWide(), application.getMarriage(), application.getAge(), application.getType(), application.getPosition(), application.getYear(), application.getPoName(), application.getPoType(), application.getPoWork(), application.getBalance(), application.getProvince(), application.getCity(), application.getCounty(), application.getTown(), application.getOnselfWork(), application.getSchool(), application.getEducation(), application.getGraduate(), application.getMajor(), application.getMajors(), application.getEnglish(), application.getChinese(), application.getCantonese(), application.getIntroduce());
	}
	
	
	@RequestMapping("/query.do")
	public void query(String name,Integer page,Integer rows,HttpServletResponse response){
		response.setCharacterEncoding("UTF-8");
		try {
			ResponseResult query = applicationServiceImpl.query(name,page,rows);
			String string = JSONObject.toJSONString(query).toString();
			response.getWriter().write(string);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	/*@RequestMapping("/query.do")
	public void query(String name,HttpServletResponse response){
		try {
			ResponseResult query = applicationServiceImpl.query(name);
			String string = JSONObject.toJSONString(query).toString();
			response.getWriter().write(string);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	*/
	
	
	
}
